/**
 * SCSS Mixins - 公共样式混入
 * 提供可复用的样式片段和布局工具
 */

// ==============================================================================
// 布局 Mixins
// ==============================================================================

// Flexbox 布局快捷方式
@mixin flex($direction: row, $justify: flex-start, $align: stretch, $wrap: nowrap) {
  display: flex;
  flex-direction: $direction;
  justify-content: $justify;
  align-items: $align;
  flex-wrap: $wrap;
}

// 水平居中
@mixin flex-center-h {
  @include flex($justify: center);
}

// 垂直居中
@mixin flex-center-v {
  @include flex($align: center);
}

// 完全居中
@mixin flex-center {
  @include flex($justify: center, $align: center);
}

// 两端对齐
@mixin flex-between {
  @include flex($justify: space-between, $align: center);
}

// 左对齐
@mixin flex-start {
  @include flex($justify: flex-start, $align: center);
}

// 右对齐
@mixin flex-end {
  @include flex($justify: flex-end, $align: center);
}

// 网格布局
@mixin grid($columns: 1, $gap: 16px) {
  display: grid;
  grid-template-columns: repeat($columns, 1fr);
  gap: $gap;
}

// ==============================================================================
// 文本 Mixins
// ==============================================================================

// 文本省略
@mixin text-ellipsis($lines: 1) {
  @if $lines == 1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  } @else {
    display: -webkit-box;
    -webkit-line-clamp: $lines;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

// 文本大小变体
@mixin text-variant($size, $weight: normal, $color: inherit) {
  font-size: $size;
  font-weight: $weight;
  color: $color;
  line-height: 1.5;
}

// ==============================================================================
// 卡片和容器 Mixins
// ==============================================================================

// 基础卡片样式
@mixin card-base($padding: 16px, $radius: 12px, $shadow: $shadow-sm) {
  background: $white;
  border-radius: $radius;
  box-shadow: $shadow;
  padding: $padding;
  overflow: hidden;
}

// 卡片变体
@mixin card-variant($padding: 16px, $radius: 12px, $shadow: $shadow-sm, $border: none) {
  @include card-base($padding, $radius, $shadow);
  
  @if $border != none {
    border: $border;
  }
  
  transition: $transition-base;
  
  &:hover {
    box-shadow: $shadow-md;
    transform: translateY(-1px);
  }
}

// 页面容器
@mixin page-container($padding: 16px) {
  min-height: 100vh;
  background: $page-bg;
  padding: $padding;
}

// ==============================================================================
// 按钮 Mixins
// ==============================================================================

// 基础按钮样式
@mixin button-base($padding: 8px 16px, $radius: 8px) {
  @include flex-center;
  gap: 6px;
  padding: $padding;
  border-radius: $radius;
  border: none;
  font-weight: 500;
  transition: $transition-base;
  cursor: pointer;
  white-space: nowrap;
  
  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
  }
}

// 按钮颜色变体
@mixin button-variant($bg-color, $text-color: white, $hover-factor: 10%) {
  @include button-base;
  background: $bg-color;
  color: $text-color;
  
  &:hover {
    background: darken($bg-color, $hover-factor);
  }
  
  &:active {
    background: darken($bg-color, $hover-factor * 1.5);
    transform: translateY(1px);
  }
}

// 渐变按钮
@mixin button-gradient($color1, $color2: darken($color1, 5%), $text-color: white) {
  @include button-base;
  background: linear-gradient(135deg, $color1 0%, $color2 100%);
  color: $text-color;
  box-shadow: 0 4px 12px rgba($color1, 0.3);
  
  &:hover {
    background: linear-gradient(135deg, darken($color1, 5%) 0%, darken($color2, 5%) 100%);
    box-shadow: 0 6px 16px rgba($color1, 0.4);
    transform: translateY(-1px);
  }
  
  &:active {
    background: darken($color1, 10%);
    transform: translateY(1px);
    box-shadow: 0 2px 6px rgba($color1, 0.4);
  }
}

// 轮廓按钮
@mixin button-outline($border-color, $text-color: $border-color, $hover-bg: $border-color) {
  @include button-base;
  background: transparent;
  color: $text-color;
  border: 2px solid $border-color;
  
  &:hover {
    background: $hover-bg;
    color: white;
  }
  
  &:active {
    background: darken($hover-bg, 10%);
  }
}

// 按钮尺寸混入
@mixin button-size($padding, $min-width: auto, $font-size: $text-base) {
  padding: $padding;
  min-width: $min-width;
  font-size: $font-size;
}

// 输入框基础样式
@mixin input-base($padding: 8px 12px, $radius: 6px) {
  padding: $padding;
  border: 1px solid $border-color;
  border-radius: $radius;
  background: $white;
  color: $text-primary;
  font-size: $text-base;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  
  &:focus {
    border-color: $primary;
    box-shadow: 0 0 0 2px rgba($primary, 0.2);
    outline: none;
  }
  
  &::placeholder {
    color: $text-disabled;
  }
}

// ==============================================================================
// 表单 Mixins
// ==============================================================================

// 表单控件基础样式
@mixin form-control-base($height: 40px, $padding: 0 12px, $radius: 8px) {
  height: $height;
  padding: $padding;
  border: 1px solid $border-color;
  border-radius: $radius;
  background: $white;
  font-size: $text-sm;
  color: $gray-800;
  transition: $transition-base;
  
  &:focus {
    border-color: $primary;
    box-shadow: 0 0 0 2px rgba($primary, 0.1);
    outline: none;
  }
  
  &:disabled {
    background: $gray-100;
    color: $gray-500;
    cursor: not-allowed;
  }
}

// 表单项布局
@mixin form-item($label-width: 80px, $gap: 12px) {
  @include flex-start;
  gap: $gap;
  margin-bottom: 16px;
  
  .form-label {
    min-width: $label-width;
    color: $gray-700;
    font-weight: 500;
    flex-shrink: 0;
  }
  
  .form-control {
    flex: 1;
  }
}

// ==============================================================================
// 动画 Mixins
// ==============================================================================

// 淡入动画
@mixin fade-in($duration: 0.3s) {
  animation: fadeIn $duration ease-in-out;
}

// 滑入动画
@mixin slide-in($direction: up, $duration: 0.3s) {
  @if $direction == up {
    animation: slideInUp $duration ease-out;
  } @else if $direction == down {
    animation: slideInDown $duration ease-out;
  } @else if $direction == left {
    animation: slideInLeft $duration ease-out;
  } @else if $direction == right {
    animation: slideInRight $duration ease-out;
  }
}

// 弹性缩放
@mixin scale-bounce($scale: 1.05, $duration: 0.2s) {
  transition: transform $duration ease;
  
  &:hover {
    transform: scale($scale);
  }
  
  &:active {
    transform: scale(0.95);
  }
}

// ==============================================================================
// 响应式 Mixins
// ==============================================================================

// 移动端适配
@mixin mobile {
  @media screen and (max-width: 480px) {
    @content;
  }
}

// 平板适配
@mixin tablet {
  @media screen and (min-width: 481px) and (max-width: 768px) {
    @content;
  }
}

// 桌面端适配
@mixin desktop {
  @media screen and (min-width: 769px) {
    @content;
  }
}

// 高分辨率适配
@mixin retina {
  @media screen and (-webkit-min-device-pixel-ratio: 2), 
         screen and (min-resolution: 192dpi) {
    @content;
  }
}

// ==============================================================================
// 工具 Mixins
// ==============================================================================

// 清除浮动
@mixin clearfix {
  &::after {
    content: '';
    display: table;
    clear: both;
  }
}

// 隐藏滚动条
@mixin hide-scrollbar {
  scrollbar-width: none; // Firefox
  -ms-overflow-style: none; // IE 10+
  
  &::-webkit-scrollbar {
    display: none; // Safari and Chrome
  }
}

// 绝对居中
@mixin absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// 占满父容器
@mixin fill-parent {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

// 文本不可选择
@mixin no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

// 硬件加速
@mixin gpu-accelerate {
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

// ==============================================================================
// 动画关键帧定义
// ==============================================================================

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideInUp {
  from { 
    opacity: 0;
    transform: translateY(20px); 
  }
  to { 
    opacity: 1;
    transform: translateY(0); 
  }
}

@keyframes slideInDown {
  from { 
    opacity: 0;
    transform: translateY(-20px); 
  }
  to { 
    opacity: 1;
    transform: translateY(0); 
  }
}

@keyframes slideInLeft {
  from { 
    opacity: 0;
    transform: translateX(-20px); 
  }
  to { 
    opacity: 1;
    transform: translateX(0); 
  }
}

@keyframes slideInRight {
  from { 
    opacity: 0;
    transform: translateX(20px); 
  }
  to { 
    opacity: 1;
    transform: translateX(0); 
  }
}